package com.chaopei.msite_web.controller;

import com.chaopei.goods_mng_api.entity.Product;
import com.chaopei.msite_web.service.ProductService;
import com.chaopei.msite_web.utils.MyTools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author Corday 天涯
 * @Date 2022/5/5 17:51
 */
@Controller
@RequestMapping("/product")
public class ProductController {
    @Resource
    private ProductService productService;

    //通过搜索查询数据 http://localhost:8080/msite/query
    //此处不适合使用mysql数据实现搜索
    //请使用专门全文搜索引擎elasticsearch简称es来实现
    @RequestMapping("/query")
    public String queryProducts(String nameCode, Map map) {
        String json = productService.getPs(nameCode);
        List<Product> ps = MyTools.getProducts(json);
        map.put("ps", ps);
        return "pages/index";
    }
}
